from typing import Dict, Any
try:
    from .utils import EnhancedOutput as Debug, OutputType as DebugType, inputMultiline
except ImportError:
    from utils import EnhancedOutput as Debug, OutputType as DebugType, inputMultiline

class AskUserTool:
    name = "ask_user"
    description = """完成的任务信息确实不足时，向用户提问。用户可以输入多行文本，以空格结束。使用场景： 1. 需要用户提供更多信息以完成任务；2.需要用户做出关键决策；3.需要用户确认重要操作；4.需要用户提供额外信息""";
    parameters = {
        "type": "object",
        "properties": {
            "question": {
                "type": "string",
                "description": "The question to ask the user"
            }
        },
        "required": ["question"]
    }

    def execute(self, args:Dict[str, Any]) -> Dict[str, Any]:
        try:
            question = args["question"]
            Debug.display(f"\nQuestion:", DebugType.TOOL)
            Debug.display(question, DebugType.SYSTEM)

            user_response = inputMultiline("Please enter your answer (input empty line to end)")
            if user_response == "__interrupt__":
                return {
                    "success":False,
                    "stdout": "",
                    "stderr":"User canceled input"
                }
            
            return {
                "success":True,
                "stdout": user_response,
                "stderr":""
            }
        except Exception as e:
            return {
                "success":False,
                "stdout": "",
                "stderr":f"Failed to ask user: {e}"
            }
        
            